<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">
      <!--<yshop-info />-->
      <div class="divBox">
        <el-row :gutter="24" class="baseInfo">
          <el-col :xs="12" :sm="12" :lg="12" class="ivu-mb">
            <el-card :bordered="false" dis-hover :padding="12">
              <div slot="header" class="acea-row row-between-wrapper">
                <span>今日待检</span>
                <el-tag type="success">全平台</el-tag>
              </div>
              <div class="content">
                <span class="content-number spBlock mb15" @click="toMylist">
                  {{ num1 }}
                  <!-- <count-to :start-val="0" :end-val="num1" :duration="2600" class="card-panel-num" /> -->
                </span>
                <!-- <el-divider></el-divider> -->
                <!-- <div class="acea-row row-between-wrapper">
                <span class="content-time">总任务数</span>
                <span>{{ count.taskSum }} </span>
              </div> -->
              </div>
            </el-card>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="12" class="ivu-mb">
            <el-card :bordered="false" dis-hover :padding="12">
              <div slot="header" class="acea-row row-between-wrapper">
                <span>本月漏检任务</span>
                <el-tag type="success">全平台</el-tag>
              </div>
              <div class="content">
                <span class="content-number spBlock mb15" @click="toMylist('now')">
                  {{ num2 }}
                  <!-- <count-to :start-val="0" :end-val="num2" :duration="3000" class="card-panel-num" /> -->
                </span>
                <el-divider />
                <div class="acea-row row-between-wrapper content-bottom" @click="toMylist('all')">
                  <span class="content-time">未补检:{{ num3 }} </span>
                  <span class="content-time">已补检:{{ num4 }}</span>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <div class="divBox">
        <el-row :gutter="24" class="dashboard-console-grid">
          <el-col :xl="18" :lg="18" :md="24" :sm="24" :xs="24">
            <el-card :bordered="false" dis-hover class="left">
              <div slot="header">
                <div class="acea-row row-middle">
                  <span class="title">
                    <el-avatar icon="el-icon-s-operation" size="small"
                      style="color: #1890ff; background: #e6f7ff; font-size: 13px" />
                    <span class="ivu-pl-8">问题提交</span>
                  </span>
                </div>
              </div>
              <el-table :data="list" element-loading-text="Loading" border fit highlight-current-row>
                <el-table-column align="center" label="ID" width="95">
                  <template slot-scope="scope">
                    {{ scope.$index }}
                  </template>
                </el-table-column>
                <el-table-column label="巡检名称">
                  <template slot-scope="scope">
                    {{ scope.row.name }}
                  </template>
                </el-table-column>
                <el-table-column label="类目">
                  <template slot-scope="scope">
                    {{ scope.row.type }}
                  </template>
                </el-table-column>
                <el-table-column label="地点">
                  <template slot-scope="scope">
                    {{ scope.row.place }}
                  </template>
                </el-table-column>
                <el-table-column label="巡检人" width="110" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.author }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="巡检时间" width="200" align="center">
                  <template slot-scope="scope">
                    {{ scope.row.display_time }}
                  </template>
                </el-table-column>
                <el-table-column label="问题描述" width="200" align="center">
                  <template slot-scope="scope">
                    {{ scope.row.desc }}
                  </template>
                </el-table-column>
                <el-table-column class-name="status-col" label="状态" width="110" align="center">
                  <template slot-scope="scope">
                    <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status | statusFilterLabel }}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="120" align="center" fixed="right">
                  <template slot-scope="scope">
                    <el-button type="primary" size="mini" :disabled="scope.row.status == '0'"
                      @click="toHandle(scope.row)">去处理</el-button>
                    <!-- <el-button type="danger" size="mini">删除</el-button> -->
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
          <el-col :xl="6" :lg="6" :md="24" :sm="24" :xs="24">
            <el-card :bordered="false" dis-hover class="right">
              <div slot="header">
                <div class="acea-row row-middle">
                  <span class="title">
                    <el-avatar icon="el-icon-message-solid" size="small"
                      style="color: #1890ff; background: #e6f7ff; font-size: 13px" />
                    <span class="ivu-pl-8">最新消息通知</span>
                  </span>
                  <el-link class="ivu-pl-8" @click="messageAll">全部 ></el-link>
                </div>
              </div>
              <div v-if="massageList && massageList.length > 0" class="content">
                <div v-for="(item, index) in massageList" :key="index" class="content-item"
                  @click="messageDetail(item)">
                  <div class="row">

                    <div class="title">{{ item.content }}</div>
                    <!-- <div class="name">{{ item.id }}</div> -->
                  </div>
                  <div class="time">{{ item.sendTime }}</div>
                </div>
              </div>
              <div v-else>
                <img src="@/assets/images/empty.png" alt="" class="empty">
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

/**
 * 记录访问，只有页面刷新或者第一次加载才会记录
 */
// count().then((res) => { });

export default {
  name: 'Dashboard',
  components: {
  },
  computed: {
    ...mapGetters(['name'])
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: 'success',
        1: 'danger'
      }
      return statusMap[status]
    },
    statusFilterLabel(status) {
      const statusMap = {
        0: '已处理',
        1: '未处理'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      pageNum: 1,
      pageSize: 5,
      massageList: [],
      num1: 25,
      num2: 32,
      num3: 22,
      num4: 10,
      list: [{
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 0,
        place: '食堂',
        desc: '线路老化'
      }, {
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 1,
        place: '食堂',
        desc: '线路老化'
      }, {
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 0,
        place: '食堂',
        desc: '线路老化'
      }]
    }
  },
  created() {
    this.$nextTick(() => {
      // this.getData()
    })
  },
  methods: {
    messageAll() {
      this.$router.push({ name: 'message' })
    },
    messageDetail(item) {
      messageRead(item.id).then(res => {
        if (item.link) {
          const sysUrl = item.link + '&name=' + encodeURIComponent(localStorage.getItem('redirectName')) + '&pwd=' + encodeURIComponent(localStorage.getItem('redirectPwd'))
          window.open(sysUrl)
        }
      })
    },
    getData() {
      const params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      messageSearch(params).then(res => {
        this.massageList = res.item.records
        console.log(this.massageList)
      })
    },
    toMylist() {
      this.$router.push({ name: 'Task' })
    },
    toHandle() {
      this.$router.push({ name: 'Issue' })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-editor-container {
  padding: 18px 22px 22px 22px;
  // background-color: rgb(240, 242, 245);

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

.acea-row {
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .title {
    display: flex;
    align-items: center;
  }

  ::v-deep.el-avatar--small {
    width: 22px;
    height: 22px;
    line-height: 22px;
  }
}

.checkTime {
  ::v-deep.el-radio__input {
    display: none;
  }
}

.ivu-pl-8 {
  margin-left: 8px;
  font-size: 14px;
}

.divBox {

  .dashboard-console-grid {
    display: flex;

    .right {
      height: 100%;
    }

    .empty {
      width: 100%;
      height: 100%;
    }
  }

}

.dashboard-console-visit {
  ::v-deep.el-card__header {
    padding: 14px 20px !important;
  }

  ul {
    li {
      list-style-type: none;
      margin-top: 12px;
    }
  }
}

.ivu-mb {
  margin-bottom: 10px;
}

.content {
  // display: flex;

  .content-item {
    margin-bottom: 15px;
    cursor: pointer;

    .row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 5px;

      .title {
        font-weight: bold;
        text-align: left;
      }

    }

    .time {
      color: #989898d7;
      font-size: 14px !important;
    }
  }

  .content-number {
    font-size: 28px;
    font-weight: 500;
  }

  .content-bottom {
    font-size: 20px;
  }

}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

.baseInfo {
  ::v-deep .el-card__header {
    padding: 15px 20px !important;
    font-size: 18px
  }
}

.divBox {
  .baseInfo {
    display: flex;
    flex-flow: row wrap;

    .el-card {
      height: 100%;
    }

    .ivu-mb {
      margin-bottom: 10px;
    }
  }
}

// .ivu-mb {
//   margin-bottom: 10px;
//   height: 100%;
// }

.up,
.el-icon-caret-top {
  color: #f5222d;
  font-size: 12px;
  opacity: 1 !important;
}

.down,
.el-icon-caret-bottom {
  color: #39c15b;
  font-size: 12px;
  /*opacity: 100% !important;*/
}

.content {
  &-number {
    font-size: 30px;
    cursor: pointer;
  }

  &-time {
    font-size: 14px;
    /*color: #8C8C8C;*/
  }

  &-total {
    font-size: 18px;

  }
}

.spBlock {
  display: block;
}
</style>
